const {LinValidator, Rule} = require('../../core/lin-validator')
const {LoginType} = require('../lib/enum')


class PositiveIntegerValidator extends LinValidator {
  constructor() {
    super()
    this.id = [
      new Rule('isInt', '需要正整数', {min: 1}),
      // new Rule('' ) 且的关系
    ]
  }
}

function checkType(vals) {
  let type = vals.body.type || vals.path.type
  if(!type){
      throw new Error('type是必填参数')
  }
  type = Number(type)
  if (!LoginType.isThisType(type)) {
      throw new Error('type参数不合法')
  }

}

class LikeValidator extends PositiveIntegerValidator {
  constructor() {
      super()
      this.validateType = checkType
  }
}


class SearchValidator extends LinValidator {
  constructor() {
    super()
    this.q = [
      new Rule('isLength','搜索关键词不能为空'), {
        min: 1,
        max: 16
      }
    ]
    this.start = [
      new Rule('isInt', 'start不符合规范', {min: 0, max: 60000}),
      new Rule('isOptional', '', 0) // 默认值
    ]
    this.count = [
      new Rule('isInt', 'count 不符合规范', {
        min: 1,
        max: 20
      }),
      new Rule('isOptional', '', 20) // 默认值
    ]
  }

}



module.exports = {
  PositiveIntegerValidator,
  LikeValidator,
  SearchValidator
}